package com.atguigu.bigdata.chapter11.window;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @Author lzc
 * @Date 2022/9/9 14:09
 */
public class Flink01_Time_pt_2 {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
        
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        
        tEnv.executeSql("create table sensor(" +
                            "   id string, " +
                            "   ts bigint, " +
                            "   vc int, " +
                            "   pt as proctime()" +
                            ")with(" +
                            "   'connector' = 'filesystem', " +
                            "   'path' = 'input/sensor.txt', " +
                            "   'format' = 'csv' " +
                            ")");
        
        tEnv.sqlQuery("select * from sensor").execute().print();
       
        
   
    }
}
/*
流中非常重要的操作:  开窗, 对窗口内的元素进行处理

sql中也要开窗, 也是要聚合的, 其实可以把窗口当成一个普通的聚合字段来理解

统计不同的传感器的水位和
    select id, sum(vc) from sensor group by id
每隔5s统计不同的传感器的水位和
    select w, wid, sum(vc) from sensor group by id, w
    
    
在sql中只支持基于时间的窗口
    事件时间
    和处理时间
    
在sql中定义窗口的时候, 需要时间, 其实就是一个时间字段(时间属性)

如何在flink-sql中添加时间属性

 */
